﻿<style>
#role, #role2 , #role3{padding-bottom:5px; padding-top:5px;border:none;}
.row .span-2 strong{font-weight:bold;}
#work2, #o2o_work{padding:10px 10px 10px 5px;}
#work_obj, #work2_obj, #work3_obj{border-bottom:1px dotted #e8e8e8;}
#work3_obj{border:none;white-space:normal;}
</style>
<div style="overflow: scroll;max-height: 500px;">
<form method="POST" action="index.php?app=desktop&ctl=users&act=saveUser" class="tableform" id="form_user">
    <div class="tableform">
        <h5>基本信息 <{help docid="101" type="link"}><{t}>点击查看帮助<{/t}><{/help}></h5>
        <div class="division">
                <table cellspacing="0" cellpadding="0" width="100%">
                    <tbody>
                    
                    <tr>
                        <th>
                            <em class="red">*</em>
                            <label for="dom_el_3e40f71"><{t}>姓名：<{/t}></label>
                        </th>
                        <td>
                            <input type="text" id="dom_el_3e40f71" value="<{$name}>" name="name" title="<{t}>姓名<{/t}>" class="x-input " autocomplete="off" vtype="required"/>
                            <{if !$ban_edit}><input type="button" onclick="new Dialog('index.php?ctl=users&act=chkpassword&id=<{$account_id}>',{width:400,height:300,title:'<{t}>密码修改<{/t}>'})" value="<{t}>修改密码<{/t}>" /><{/if}>
                        </td>
                    </tr>        
                    
                    <tr>
                        <th>
                            <label for="dom_el_3e40f72"><{t}>工号：<{/t}></label>
                        </th>
                        <td>
                            <input type="text" id="dom_el_3e40f72" value="<{$op_no}>" name="op_no" title="<{t}>工号<{/t}>" class="x-input " autocomplete="off"/>
                        </td>
                    </tr>
                    
                    <{if ($ismyself != 'true') && (!$super)}>
                    <tr>
                        <th>
                            <em class="red">*</em>
                            <label for="dom_el_3e40f73"><{t}>启用：<{/t}></label>
                        </th>
                        <td>
                            <select id="dom_el_3e40f73" required="1" name="status" type="select" title="<{t}>启用<{/t}>" class="x-input-select inputstyle">
                                <option value="0" <{if !$status}>selected="selected"<{/if}>><{t}>否<{/t}></option>
                                <option value="1" <{if $status}>selected="selected"<{/if}>><{t}>是<{/t}></option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                       <th>是否显示价格</th>
                       <td>
                            <input type="radio" name="is_price" value='true' required checked="checked"<{if $is_price == 'true'}>checked<{/if}> />是
                            <input type="radio" name="is_price" value='false' required <{if $is_price == 'false'}>checked<{/if}> />否
                       </td>
                    </tr>
                    <{/if}>
                    <input type="hidden" value="<{$account_id}>" name="account_id" />
                </tbody>
            </table>
        </div>
    </div>
  <{ if(!$super) }>
  <div class="tableform">
    <h5>前端店铺权限</h5>
    <div class="gridlist clearfix">
      <div class="row" id="shops">
        <div class="row-line shops-list" style="padding:5px;">
          <div class="span-2"><strong>所属店铺</strong></div>

          <div class="span-2">
            <label><input type="checkbox" class='selectall' onclick="this.blur()">全选</label>
          </div>
          <div class="span-13">
            <{foreach from=$workgroup_shops item=item}>
            <div class="span-auto">
              <label><input class="shopIds" type="checkbox" value="<{$item.shop_id}>" name="shopIds[]" <{if in_array($item.shop_id, $shopIds) }>checked='checked'<{/if}> /><{$item.name}></label>
            </div>
            <{/foreach}>
          </div>
        </div>
      </div>
    </div>
  </div>
  <{/if}>
<div class="tableform"  <{if !$super}><{else}>style="display:none"<{/if}>>
    <h5>工作组</h5>
    <div class="gridlist clearfix" <{if !$super}><{else}>style="display:none"<{/if}> >
        <{if !$super}><input type='hidden'  vtype='requiredcheckbox'/> <{/if}>
            <div class="row" id="role">
                <div class="row-line role-list" style="padding:5px;">
                    <div class="span-2"><strong>订单角色</strong></div>
                    <div class="span-13">
                        <{foreach from=$workgroup_order item=item}>
                        <div class="span-auto">
                            <label><input class="role" type="checkbox" value='<{$item.role_id}>' name="role[<{$item.role_id}>]" <{if $item.checked=='true'}>checked='checked'<{/if}> /><{$item.role_name}></label>
                        </div>
                        <{/foreach}>
                    </div>
                </div>
            </div>
            <div class="row" id="work_obj" <{if $per.order}><{else}>style="display:none;"<{/if}> >
                <div class="row-line role-list" style="padding:10px;">
                    <div id="work" style="padding-left:70px;"><{$per.order}></div>
                </div>
            </div>
            
            <div class="row" id="role2">
                <div class="row-line role-list" style="padding:5px;">
                    <div class="span-2"><strong>仓库角色</strong></div>
                    <div class="span-13">
                        <{foreach from=$workgroup_branch item=item}>
                        <div class="span-auto">
                            <label><input class="role2" type="checkbox" value='<{$item.role_id}>' name="role[<{$item.role_id}>]" <{if $item.checked=='true'}>checked='checked'<{/if}> /><{$item.role_name}></label>
                        </div>
                        <{/foreach}>
                    </div>
                </div>
            </div>
            <div class="row" id="work2_obj" <{if $per.branch}><{else}>style="display:none;"<{/if}> >
                <div class="row-line role-list" id="work2">
                    <{$per.branch}>
                </div>
                <input type="hidden" id="work3" value=""></input>
            </div>
            
            
            <div class="row" id="role3">
                <div class="row-line role-list" style="padding:5px;">
                    <div class="span-2"><strong>门店角色</strong></div>
                    <div class="span-13">
                        <{foreach from=$workgroup_o2o_branch item=item}>
                        <div class="span-auto">
                            <label><input class="role3" type="checkbox" value="<{$item.role_id}>" name="role[<{$item.role_id}>]" <{if $item.checked=='true'}>checked='checked'<{/if}> /><{$item.role_name}></label>
                        </div>
                        <{/foreach}>
                    </div>
                </div>
            </div>
            <div class="row" id="work3_obj"  <{if $per.o2o_branch}><{else}>style="display:none;"<{/if}> >
                <div class="row-line role-list" id="o2o_work">
                    <{$per.o2o_branch}>
                </div>
            </div>

    </div>
    
    
</div>
 <table>
          <tr>
            <th>所属组织：</th>
            <td><input type="text" size="30" name="srcorg" value="<{$srcorg}>"/></td>
            <th>所属区域：</th>
            <td>
            <select name="area" id="area">
                    <option value="重庆" <{if $area =='重庆'}> selected="selected"<{/if}>><{t}>重庆<{/t}></option>
                    <option value="新疆" <{if $area =='新疆'}> selected="selected"<{/if}>><{t}>新疆<{/t}></option>
                    <option value="登鹏" <{if $area =='登鹏'}> selected="selected"<{/if}>><{t}>登鹏<{/t}></option> 
                </select>
                </td>
                <!-- <th>
                            <em class="red">*</em>
                            <label for="area"><{t}>所属区域：<{/t}></label>
                        </th>
                        <td>
                            <select id="area" required="1" name="area" type="select" title="<{t}>所属区域<{/t}>">
                                <option value="重庆" <{if !$area}>selected="selected"<{/if}>><{t}>重庆<{/t}></option>
                                <option value="新疆" <{if $area}>selected="selected"<{/if}>><{t}>新疆<{/t}></option>
                                <option value="登鹏" <{if $area}>selected="selected"<{/if}>><{t}>登鹏<{/t}></option>
                            </select>
                        </td> -->
          </tr>
         </table>
<div class="table-action">
        <{button type="button"  label=$___desktop="保存"|t:'desktop' id="user-submit"}>
</div>

</form>
</div>

<script>
//订单角色
var show_group = 3;
//仓库角色
var show_branch = 2;
//门店角色
var show_o2o_branch = 99;

//根据组织架构加载选择门店的option
function load_organization_stores_list(org_id,value,action){
    if (action == "onchange" && org_id == '_NULL_') {
        //在选择过程中 选择了 “请选择...” 选择门店options 这里自动显示父类下拉框的门店信息
        var org_id = "";
        if (value) {
            var arr_cur_select = value.split(":");
            org_id = arr_cur_select[2];
        }
    }
    new Request({
        url : "index.php?app=o2o&ctl=admin_branch_product&act=organization_stores_list",
        async : false,
        method : 'post',
        data : {
            p_org_id : org_id,
        },
        onComplete : function(store_html) {
            $("organization_stores_list").set('html', store_html);
            filter_store_list_by_org();
        }
    }).send();
}

//选择组织架构时 根据填写的门店名称 过滤最终选择门店的option
function filter_store_list_by_org(){
    var store_name_val = $("store_name_filter").getValue().trim();
    get_store_list(store_name_val);
}

//onblur事件根据填写的门店名称 过滤最终选择门店的option
function filter_store_list(obj){
    var store_name_val = obj.getValue().trim();
    get_store_list(store_name_val);
}

function get_store_list(store_name_val){

    var select_store_name = $("organization_stores_list").getElements("option:selected")[0].text;
    //如果门店名称和选择项不一样 默认给请选择... 来重新选择
    if(select_store_name.indexOf(store_name_val) == -1 && select_store_name != "请选择..."){
        $("organization_stores_list").getElements("option")[0].selected=true;
        $("organization_stores_list").getElements("option:selected")[0].text = "请选择...";
    }
    //先显示当前组织架构的门店option
    $("organization_stores_list").getElements("option").each(function(item){
        item.removeAttribute("style");
    });
    if(!store_name_val){
        return false;
    }
    //过滤option项
    $("organization_stores_list").getElements("option").each(function(item){
        if(item.value == "_NULL_"){
            //不过滤 请选择选项
            return true;
        }
        if(item.text.indexOf(store_name_val) == -1){
            //不符合填写内容的过滤掉
            item.setAttribute("style","display:none");
        }
    });
}

(function(){
  
    $$('.role').addEvent('click',function(e){
           //订单权限
          var show_group_info = document.getElementById("work").innerHTML;
          //仓库权限
          var show_branch_info = document.getElementById("work2").innerHTML;
          var checkedEl = $ES('input.role:checked');

          var checkedName = [];
          checkedEl.each(function(cel,k){
            checkedName[k] = encodeURIComponent(cel.value=cel.value.trim());
          });
        //获取仓库角色的信息
            var checked_branch = $ES('input.role2:checked');
            var checkedName_branch  = [];
            checked_branch.each(function(cel,k){
                checkedName_branch[k] = encodeURIComponent(cel.value=cel.value.trim());
              });
          
          
          new Request({
              url:'index.php?app=desktop&ctl=users&act=detail_ground',
              //update:$('work'),
              method:'post',
              data:'role='+show_group+'&checkedName='+JSON.encode(checkedName)+'&checkedName_branch='+JSON.encode(checkedName_branch)+'&name='+encodeURIComponent(this.value=this.value.trim()),
                onComplete:function(result){
                      var result = JSON.decode(result);
                      var group_Info = document.getElementById("work");
                      var branch_info = document.getElementById("work2");

                      //订单确认下拉
                      //group_Info.innerHTML = result['group_info']||'';
                      if(result['group_info'])
                      {
                          $('work_obj').setStyle('display','');
                          group_Info.innerHTML = result['group_info'];
                      }
                      else
                      {
                          group_Info.innerHTML = '';
                          $('work_obj').setStyle('display','none');
                      }
                      
                      //选择仓库
                      //branch_info.innerHTML = result['branch_info']||'';
                      if(result['branch_info'])
                      {
                          $('work2_obj').setStyle('display','');
                          branch_info.innerHTML = result['branch_info'];
                      }
                      else
                      {
                          branch_info.innerHTML = '';
                          $('work2_obj').setStyle('display','none');
                      }
                  }
          }).send();
          // $('work').setStyle('display','block');
        });
      $$('.role2').addEvent('click',function(e){
            var checkedEl = $ES('input.role2:checked');

            var checkedName = [];
            checkedEl.each(function(cel,k){
            checkedName[k] = encodeURIComponent(cel.value=cel.value.trim());
            });
            
            //获取订单角色的信息
            var checked_group = $ES('input.role:checked');
            var checkedName_group  = [];
            checked_group.each(function(cel,k){
                checkedName_group[k] = encodeURIComponent(cel.value=cel.value.trim());
              });
            new Request({
              url:'index.php?app=desktop&ctl=users&act=detail_ground',
              //update:$('work2'),
              method:'post',
              data:'role='+show_branch+'&checkedName='+JSON.encode(checkedName)+'&checkedName_group='+JSON.encode(checkedName_group)+'&name='+encodeURIComponent(this.value=this.value.trim()),
              onComplete:function(result){
                  var result = JSON.decode(result);
                  var group_Info = document.getElementById("work");
                  var branch_info = document.getElementById("work2");
                  //设置双重权限的标识位信息
                  var branch_work3 = document.getElementById("work3");
                  //订单确认下拉
                  //group_Info.innerHTML = result['group_info']||'';
                  if(result['group_info'])
                  {
                      $('work_obj').setStyle('display','');
                      group_Info.innerHTML = result['group_info'];
                  }
                  else
                  {
                      group_Info.innerHTML = '';
                      $('work_obj').setStyle('display','none');
                  }
                  
                  //选择仓库
                  //branch_info.innerHTML = result['branch_info']||'';
                  if(result['group_info']){
                      //1标示存在双重权限
                      branch_work3.value = '1';
                  }else{
                      branch_work3.value = '0';
                  }
                  
                  if(result['branch_info'])
                  {
                      $('work2_obj').setStyle('display','');
                      branch_info.innerHTML = result['branch_info'];
                  }
                  else
                  {
                      branch_info.innerHTML = '';
                      $('work2_obj').setStyle('display','none');
                  }
              }
            }).send();
            // $('work').setStyle('display','block');
          });
       
     if($('is_super'))
     $('is_super').addEvent('change',function(e){  
            value = this.value;
            if(value==0){
                $('role').setStyle('display','block'); 
                //$('work').setStyle('display','block');
                
                $('work_obj').setStyle('display','block');
                $('role2').setStyle('display','block');
            } 
            else{
                $('role').setStyle('display','none'); 
                //$('work').setStyle('display','none');
                
                $('work_obj').setStyle('display','none');
                $('role2').setStyle('display','none');
            }       
            
        });
    
})();

</script>

<script>
(function(){
    var _form = $('form_user');
    var btn =$('user-submit');
    var finder = finderGroup['<{$env.get._finder.finder_id}>'];
    
    _form.store('target',{
        onSuccess:function(response){
            var hash_res_obj = JSON.decode(response);
        
            if (hash_res_obj.success != undefined && hash_res_obj.success != "")
            {
                try{
                    var _dialogIns = btn.getParent('.dialog').retrieve('instance');
                }catch(e){}
                
                if(_dialogIns)
                {    
                    _dialogIns.close();
                    window.finderGroup['<{$env.get._finder.finder_id}>'].refresh();
                }
            }
            
        }
    });

        btn.addEvent('click',function(){
        
            _form.fireEvent('submit',{stop:$empty});
            
        
        
        });


    $E('.selectall').addEvent('click',function(e){
    
       if (this.checked)
        {
            $ES('.shopIds').set('checked','checked');
            $$('.shopIds').each(function(item){
                protr = item.getParent('tr');
                product_id = protr.get('key');
                protr.addClass('selected');
                pag.selectData(product_id).selected=true;
            
            });
        }else{
            $ES('.shopIds').set('checked','');
            $$('.shopIds').each(function(item){
                protr = item.getParent('tr');
                product_id = protr.get('key');
                protr.removeClass('selected');
                pag.selectData(product_id).selected=false;
            
            });
        }
        
    
    
    });

    $$('.role3').addEvent('click',function(e)
    {
        var checkedEl = $ES('input.role3:checked');
    
        var checkedName = [];
        checkedEl.each(function(cel,k){
            checkedName[k] = encodeURIComponent(cel.value=cel.value.trim());
        });
        
        //获取订单角色的信息
        var checkedName_group  = [];
        
        new Request({
          url:'index.php?app=desktop&ctl=users&act=detail_ground',
          method:'post',
          data:'role='+show_o2o_branch+'&checkedName='+JSON.encode(checkedName)+'&checkedName_group='+JSON.encode(checkedName_group)+'&name='+encodeURIComponent(this.value=this.value.trim()),
          onComplete:function(result){
              var result = JSON.decode(result);
              
              if(result == null)
              {
                  return false;
              }
              
              //选择o2o门店仓库
              var o2o_branch_info = document.getElementById("o2o_work");
              if(result['o2o_branch_info'])
              {

                  $('work3_obj').setStyle('display','');
                  o2o_branch_info.innerHTML = result['o2o_branch_info'];
              }
              else
              {
                  o2o_branch_info.innerHTML = '';
                  $('work3_obj').setStyle('display','none');
              }
          }
        }).send();
    });
})();
    
    
</script>

